/**
 * @file Utils.cpp
 * @brief Utility functions for the contingent system, implementation of the functions defined in Utils.hpp
 * @date 2024-2-27
*/

#include "contbtsys_core/Utils.hpp"

namespace ContBTSys {

void print_action_tree(RootPtr root) {
    if (root == nullptr) {
        std::cout << " ===  end of this branch ===" << std::endl;
        return;
    }
    if (root->get_type() == ActionType::ACTUATION) {
        std::cout << "Actuation: " << root->get_name() << std::endl;
        if (root->son != nullptr) {
            std::cout << "Son: " << root->son->get_name() << std::endl;
            std::cout << " ========================= " << std::endl;
            print_action_tree(root->son);
        } else {
            std::cout << " Son: end " << std::endl;
        }
    } else {
        std::cout << "Observation: " << root->get_name() << std::endl;
        if (root->true_son != nullptr && root->false_son != nullptr) {
            std::cout << "TrueSon: " << root->true_son->get_name() 
                      << "\tFalseSon: " << root->false_son->get_name() << std::endl;
            std::cout << " ========================= " << std::endl;
            print_action_tree(root->true_son);
            print_action_tree(root->false_son);
        } else {
            std::cout << " TrueSon/FalseSon: end " << std::endl;
        }
    }
}

} // namespace ContBTSys

